/*********************************************************************************
    This software is created under the term GNU General Public License.
    You should have received a copy of the GNU General Public License.
    If not, write to the Free Software Foundation, 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.

list_cir:
    a implement of list, using data structure double linked list. it is not a
    part of interface, but a part of implement of interface list. you
    can use it through interface list.

author: xiangyun.kong(lo-sor@hotmail.com)
create: 2-26-2011

changes:

**********************************************************************************/
#ifndef __clib_list_link_h__
#define __clib_list_link_h__

#include <std.h>
#include <inttype.h>

/// double linked list
typedef struct _list_link_node
{
    void* val;
    struct _list_link_node* next, *pre;
} list_link_node, *ltl_iterator;

typedef struct _list_link
{
    list_link_node *head;
    list_link_node *tail;
    int32 size;
} list_link ;

/// create a new list
list_link* ltl_create();
/// destroy an existed list
void ltl_destroy( list_link* _lt );
/// get the count of datas in the list
int32 ltl_size( list_link* _lt );

/// push data to the back of the list
void ltl_pushb( list_link* _lt, void* _val );
/// push data to the front of the list
void ltl_pushf( list_link *_lt, void *_val );
/// insert a new data to the list, behind the iterator
ltl_iterator ltl_insert( list_link *_lt, ltl_iterator _it, void *_val );
/// insert a new data to the list, at the pos-th position
/// 0 <= _pos < ltc_size()
ltl_iterator ltl_insertp( list_link *_lt, int32 _pos, void *_val );

/// get the value of iterator
void* ltl_val( ltl_iterator _it );
/// get the pos-th data in the list
void* ltl_get( list_link *_lt, int32 _pos );
/// get the data at the front of the list
void* ltl_front( list_link *_lt );
/// get the data at the back of the list
void* ltl_back( list_link *_lt );
/// get the first iterator
ltl_iterator ltl_begin( list_link *_lt );
/// get the last position, which is next to the last data(insertion 
/// place), of the list
ltl_iterator ltl_end( list_link *_lt );
/// get the next to the iterator
ltl_iterator ltl_next( ltl_iterator _it );
/// get the previous to the iterator
ltl_iterator ltl_pre( ltl_iterator _it );
/// get the first iterator which data matches the key.
/// fun( _key, ltc_val(iterator) ) == 0 means the iterator matches
/// the key
ltl_iterator ltl_find( list_link *_lt, void *_key, compare _fun );

// the following functions will delete data from list
// {3 delete begin

/// list pop front
void* ltl_popf( list_link *_lt );
/// list pop back
void* ltl_popb( list_link *_lt );
/// remove the iterator( and it's data from list )
/// return the data
void* ltl_remove( list_link *_lt, ltl_iterator _it );
/// remove the pos-th data from the list
/// return the data
void* ltl_removep( list_link *_lt, int32 _pos );

// delete finished 3}

// sort ascend the list.
void ltl_sort( list_link *_lt, compare _fun );


#endif // __clib_list_link_h__
